<?php
/**
 * 
 *
 * @copyright	Copyright 2009-2010   深圳市饭后科技有限公司
 * @license	LGPL (http://www.gnu.org/licenses/lgpl.html)
 * @author	XinHui Wang <wangxinhui@fanhougame.com
 * @package	autoweb xhprof
 * @version	2867
 * @link		http://fanhougame.com/
 */
class Xhprof
{
	
	private $xhprof;
	
	public function __construct()
	{
		if(function_exists('xhprof_enable'))
		{
			//同时分析CPU和Mem的开销
			xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);
			$xhprof=true;
		}
		$xhprof=false;
	}
	
	
	public function exec()
	{
		if(!$this->xhprof)
			return false;
		
		$xhprof_data = xhprof_disable();
		include_once HZHIHU_ROOT."helpers/xhprof/xhprof_lib/utils/xhprof_lib.php";
		include_once HZHIHU_ROOT."helpers/xhprof/xhprof_lib/utils/xhprof_runs.php";
		$xhprof_runs = new XHProfRuns_Default();
		$run_id = $xhprof_runs->save_run($xhprof_data, "default");
		return '<a href="'.HZHIHU_URL.'helpers/xhprof/xhprof_html/index.php?run='.$run_id.'&source=default" target="_blank">统计</a>';
				
	}
	
	public function getxhprof()
	{
		return $this->xhprof;
	}
}
